<template>
	<!-- 搜索框 -->
	<view class="search">
		<input type="text" placeholder="搜索" class="searchInput" />
		<button class="searchButton">搜索</button>
	</view>
	<!-- 轮播图 -->
	<view class="swiper">
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" class="swiperImage">
			<swiper-item v-for="item in swiperList" :key="item" class="swiperImage">
				<image :src="item.img" mode="" class="swiperImage"></image>
			</swiper-item>
		</swiper>
	</view>
	<!-- 菜单 -->
	<view class="menu">
		<view v-for="item in menuList" :key="item.id" class="menuone">
			<image :src="item.icon" mode="" class="menuImage"></image>
			<view>
				{{item.title}}
			</view>
		</view>
	</view>
	<view class="textshow">
		<text>———— 商品列表 ————</text>
	</view>
	<!-- 商品列表 -->
	<view>
		<view class="prolist">
			<view v-for="item in proList" :key="item.proid" class="prodiv">
				<view>
					<image :src="item.img1" mode="" class="proImage"></image>
				</view>
				<view class="protext">
					<view>
						{{item.proname}}
					</view>
					<view style="color: #ff4444;">
						<text style="font-size: 24rpx;">￥</text>
						<text style="font-size: 36rpx;font-weight: bold;">{{item.originprice}}</text>
					</view>
					<view class="proTag">
						<text class="tag">包邮</text>
						<text class="tag">热销</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				proList: [], //存储商品列表数据
				swiperList: [], //存储轮播图数据
				menuList: [], //存储菜单数据
				num: 1 //获取商品列表的页码
			}
		},
		onLoad() {

		},
		methods: {
			// 请求商品列表数据函数
			proListLoad() {
				uni.request({
					url: 'http://47.94.6.186:3001/api/pro/list',
					method: 'GET',
					data: {
						count: this.num,
						limitNum: 10
					},
					success: (res) => {
						this.proList = [...this.proList, ...res.data.data]
					}
				})
			},
			// 请求轮播图数据函数
			swiperListLoad() {
				uni.request({
					url: 'http://47.94.6.186:3001/api/banner/list',
					method: 'GET',
					success: (res) => {
						this.swiperList = res.data.data
					}
				})
			},
			// 请求菜单数据函数
			menuListLoad() {
				uni.request({
					url: 'http://47.94.6.186:3001/api/menu/list',
					method: 'GET',
					success: (res) => {
						this.menuList = res.data.data
					}
				})
			}
		},
		// 滚动到底部加载下一页的数据并展示
		onReachBottom() {
			this.num++;
			this.proListLoad();
		},
		// 下拉刷新，重新请求第一页的数据展示
		onPullDownRefresh() {
			this.proList = [];
			this.num = 1;
			this.proListLoad();
			uni.stopPullDownRefresh()
		},
		mounted() {
			this.proListLoad()
			this.swiperListLoad()
			this.menuListLoad()
		}
	}
</script>

<style>
	/* 搜索模块样式 */
	.search {
		height: 80rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 2rpx;
		margin-bottom: 5rpx;
	}

	.searchInput {
		width: 78%;
		border: 2rpx solid black;
		border-color: chocolate;
		height: 80rpx;
		border-radius: 80rpx;
		padding-left: 30rpx;
		box-sizing: border-box;
	}

	.searchButton {
		height: 80rpx;
		text-align: center;
		line-height: 80rpx;
		background-color: chocolate;
	}

	/* 轮播图模块样式 */
	.swiper {
		width: 100%;
		height: 400rpx;
	}

	.swiperImage {
		width: 100%;
		height: 100%;
	}

	/* 菜单模块样式 */
	.menu {
		width: 98%;
		height: 260rpx;
		margin: 0 auto;
		border: 2rpx solid gainsboro;
		margin-top: 20rpx;
		border-radius: 20rpx;
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;
		align-items: center;
	}

	.menuone {
		width: 140rpx;
		font-size: 28rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.menuImage {
		width: 100rpx;
		height: 80rpx;
	}

	.textshow {
		height: 90rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		color: gray;
		font-size: 38rpx;
	}

	/* 商品列表模块样式 */
	.prolist {
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;
	}

	.prodiv {
		width: 49%;
		height: 600rpx;
		display: flex;
		background-color: #F8F8F8;
		flex-direction: column;
		align-items: center;
		border-radius: 30rpx;
	}

	.proImage {
		border-top-right-radius: 30rpx;
		border-top-left-radius: 30rpx;
		width: 350rpx;
		height: 400rpx;
	}

	.protext {
		width: 98%;
		flex: 1;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
		border-bottom-right-radius: 30rpx;
		border-bottom-left-radius: 30rpx;
		background-color: #ffffff;
		align-self: flex-start;
		display: flex;
		flex-direction: column;
		justify-content: space-evenly;
	}

	.proTag {
		display: flex;
		gap: 30rpx;
	}

	.tag {
		font-size: 20rpx;
		color: #ff6b6b;
		background: rgba(255, 68, 68, 0.1);
		padding: 4rpx 12rpx;
		border-radius: 12rpx;
	}
</style>